using System;
using System.Drawing;
using Emgu.CV;
using Emgu.CV.Structure;
using NIPO.Data;
using NIPO.Plugins;

namespace NIPOCvPlugins.PeopleDetectorPlugin
{
    public class PeopleDetectorProcessingPlugin:ProcessingPlugin
    {
        private Emgu.CV.HOGDescriptor _hog;
        #region Overrides of Plugin

        protected override void Initialize()
        {
            _hog = new Emgu.CV.HOGDescriptor();
        }

        public override void Dispose()
        {
        }

        public override bool IsConfigured
        {
            get { return true; }
        }

        #endregion

        #region Overrides of IPOPlugin

        public override void Reset()
        {
            
        }

        #endregion

        #region Overrides of ProcessingPlugin

        public override void ProcessData(object sender, NIPOEventArgs e)
        {
            if (!(e.Data is GenericDTO<Image<Bgr, byte>>))
                return;
            Image<Bgr, byte> img = (e.Data as GenericDTO<Image<Bgr, byte>>).Value;
            Rectangle[] rectangles = _hog.DetectMultiScale(img);
            foreach (Rectangle rectangle in rectangles)
            {
                img.Draw(rectangle, new Bgr(Color.Red), 2);
            }
            RaiseNewData(new GenericDTO<Image<Bgr, byte>>(img, "EMGU/Image<Bgr, byte>", img.Data.Length, DateTime.Now));
        }

        #endregion
    }
}